package com.service.alarm;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import com.service.bean.alarm.AlarmInfo;
import com.service.bean.alarm.AlarmRule;
import com.service.bean.area.Area;
import com.service.bean.area.Road;
import com.service.bean.device.Vehicle;
import com.service.bean.other.VariableData;

import com.service.bean.point.GarbageCollectionPoint;
import com.service.bean.point.LabelPoint;

import com.service.bean.point.Point;
import com.service.bean.point.RoadCheckPoint;
import com.service.bean.signal.GpsSignal;
import com.service.cache.CacheManager;
import com.service.calculate.vehicle.SignalCreator;
import com.service.other.Logger;
import com.service.other.ServerConfig;
import com.service.socket.process.SendCommand;
import com.service.tools.AlarmTool;
import com.service.tools.Tools;

public class AlarmFunction {
	/**
	 * yyyy-MM-dd HH:mm:ss
	 */
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	/**
	 * yyyy-MM-dd
	 */
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
	
	// ---------------------------硬件报警---------------------------
	
	/**
	 * 油量报警  
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm102(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.oilExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "油量过低，当前油量剩余[" + signal.oilAmt + "%]!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 油耗异常报警 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm103(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.oilMutation) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "油耗异常,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 臭味超标 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm110(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.odorExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请注意,臭味值已超标!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 液压油报警 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm111(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.hydOilExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "液压油过低,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 扫盘未下落 
	 * @param vehicle
	 * @param 
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm112(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.isInWork && 1 == signal.broomCanNotDown) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "扫盘未下落,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 扫盘转速异常 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm113(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.isInWork && 1 == signal.broomSpeedExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "扫盘转速异常,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 吸嘴未下落 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm114(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.isInWork && 1 == signal.nozzleCanNotDown) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "吸嘴未下落,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 工作未喷水 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm115(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		// 不是太仓项目,原有报警逻辑
		if(!"048".equals(signal.companyCode)){
			if (1 == signal.isInWork && 1 == signal.broomOpenNoWatering) {
				ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "工作未喷水,请检查!";
				ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
				return ai;
			}
		} else {
			// 太仓项目下的洗扫车、高压冲洗车、洒水车不判断
			if ((2 != signal.equipmentType && 4 != signal.equipmentType && 5 != signal.equipmentType)) {
				return ai;
			}
			// acc关闭，不判断 ||  非工作状态，不判断
			if(0 == signal.accStatus || 0 == signal.isInWork){
				return ai;
			}
			if (4 == signal.equipmentType && 1 == signal.wateringStatus) {
				return ai;
			} else if (3 == signal.wateringStatus) {
				return ai;
			}
			// 报警
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			if (4 == signal.equipmentType && 0 == signal.wateringStatus) {
				ai.alarmMessage = "工作时喷头未喷水!";
			} else if (0 == signal.wateringStatus) {
				ai.alarmMessage = "工作时左右喷头均未喷水!";
			} else if (1 == signal.wateringStatus) {
				ai.alarmMessage = "工作时左喷头未喷水!";
			} else if (2 == signal.wateringStatus) {
				ai.alarmMessage = "工作时右喷头未喷水!";
			}
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}
	/**
	 * 水流喷头未打开 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm116(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.isInWork && 1 == signal.waterNozzleExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "水流喷头未打开,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 高压喷杆未打开
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm117(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.isInWork && 1 == signal.isLanceOpen) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "高压喷杆未打开,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 主发动机转速异常 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm118(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.motorSpeedExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请注意,主发转速异常,当前转速[" + signal.majSpeed + "r/min].";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 作业超速报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm122(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		// 获取缓存变量
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		// 非工作或者速度小于设定值，清缓存
		if (null == rule.value1 || null == rule.value2 || 0 == signal.isInWork
				|| signal.speed <= Integer.parseInt(rule.value1)) {
			variable.alarmTime122 = null;
			return null;
		}
		// 间隔为0，每条超速的gps都算一条报警
		if (0 == Integer.parseInt(rule.value2)) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "工作时速度过快,请按规定的速度作业!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		if (variable.alarmTime122 == null) {
			// 记录第一次触发报警时间
			variable.alarmTime122 = signal.gpsTime;
		} else {
			long time = (signal.gpsTime.getTime() - variable.alarmTime122.getTime()) / 1000L;
			if (time >= Integer.parseInt(rule.value2) * 60) {
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "工作时速度过快,请按规定的速度作业!";
				ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
				// 产生一条报警清楚缓存,重新计算
				variable.alarmTime122 = null;
				return ai;
			}
		}
		return null;
	}
	
	/**
	 * 副发动机转速异常
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm201(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.auxiMotorSpeedExc) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请注意,副发转速异常,当前转速[" + signal.subSpeed + "r/min].";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 设备故障
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm202(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.terminalFault) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "设备故障,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 传感器故障 
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm203(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.output12vStatus) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "传感器故障,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	// ---------------------------软件报警---------------------------
	
	/**
	 * 区域/路线超速报警
	 * @param vehicle 
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm101(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		// 获取缓存变量
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		//有排班，不在排班时间内不报警
		if (!AlarmTool.calDutyAndAreaAlarm(vehicle, signal)) {
			// 非工作时间段内, 清缓存
			variable.overSpeedTime = null;
			variable.lastAlarmTime101 = null;
			return null;
		}
		if (null == signal.areaId) {
			// 不在任一规划/排班区域内, 清缓存
			variable.overSpeedTime = null;
			variable.lastAlarmTime101 = null;
			return null;
		}
		if (signal.speed <= Double.valueOf(rule.value1)) {
			// 当前速度小于报警阀值, 清缓存
			variable.overSpeedTime = null;
			variable.lastAlarmTime101 = null;
			return null;
		}
		if (variable.overSpeedTime == null) {
			// 第一次触发报警, 记录当前时间
			variable.overSpeedTime = signal.gpsTime;
		} else {
			long time = (signal.gpsTime.getTime() - variable.overSpeedTime.getTime()) / 1000L;
			if (time >= Integer.valueOf(rule.value2) * 60) {
				if (variable.lastAlarmTime101 == null) {
					variable.lastAlarmTime101 = signal.gpsTime;
					// 生成语音命令,发送给下位机
					String command = AlarmTool.getVoiceRemindingCommand(1);
					SendCommand.voiceReminding(signal.gpsNo, command);
					// 生成报警
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "行驶速度规定为[" + rule.value1 + "km/h], 您已超速行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
				long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime101.getTime()) / 1000L;
				if (time1 >= Integer.valueOf(rule.value2) * 60) {
					variable.lastAlarmTime101 = signal.gpsTime;
					String command = AlarmTool.getVoiceRemindingCommand(1);
					SendCommand.voiceReminding(signal.gpsNo, command);
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "行驶速度规定为[" + rule.value1 + "km/h], 您已超速行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
				return null;
			}
		}
		return null;
	}
	
	/**
	 * 未按规定路线行驶报警 ok
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm107(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (!AlarmTool.calDutyAndAreaAlarm(vehicle, signal)) {
			// 非工作时间段内,清缓存
			variable.outOfRoadTime = null;
			variable.lastAlarmTime107 = null;
			return null;
		}
		if (0 == signal.accStatus) {
			// 车辆acc关闭,清缓存
			variable.outOfRoadTime = null;
			variable.lastAlarmTime107 = null;
			return null;
		}
		if (0 == signal.isInWork && null != signal.areaId) {
			// 车辆当前处于非工作状态,并且在规划/排班的区域中时,清缓存
			variable.outOfRoadTime = null;
			variable.lastAlarmTime107 = null;
			return null;
		}
		if (1 == signal.isInWork && null != signal.areaId) {
			// 是工作状态, 并且在区域中
			if ("01".equals(vehicle.getAreas().get(signal.areaId).kind)) {
				// 如果有重叠区域, 以工作区域优先
				// 工作状态,在工作区域中,清缓存
				variable.outOfRoadTime = null;
				variable.lastAlarmTime107 = null;
				return null;
			}
		}
		if (variable.outOfRoadTime == null) {
			variable.outOfRoadTime = signal.gpsTime;
		} else {
			long time = (signal.gpsTime.getTime() - variable.outOfRoadTime.getTime()) / 1000L;
			if (time >= Integer.valueOf(rule.value1) * 60) {
				if (variable.lastAlarmTime107 == null) {
					variable.lastAlarmTime107 = signal.gpsTime;
					// 发送语音报警命令
					String command = AlarmTool.getVoiceRemindingCommand(2);
					SendCommand.voiceReminding(signal.gpsNo, command);
					// 生成报警
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "您已未按规定路线行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
				long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime107.getTime()) / 1000L;
				if (time1 >= Integer.valueOf(rule.value1) * 60) {
					variable.lastAlarmTime107 = signal.gpsTime;
					String command = AlarmTool.getVoiceRemindingCommand(2);
					SendCommand.voiceReminding(signal.gpsNo, command);
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "您已未按规定路线行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
				return null;
			}
		}
		return null;
	}
	
	/**
	 * 出区域报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm108(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (!AlarmTool.calDutyAndAreaAlarm(vehicle, signal)) {
			// 非工作时间段内,清缓存
			variable.outOfAreaTime = null;
			variable.lastAlarmTime108 = null;
			return null;
		}
		if (null != signal.areaId) {
			// 在区域中,清缓存
			variable.outOfAreaTime = null;
			variable.lastAlarmTime108 = null;
			return null;
		}
		if (null == variable.outOfAreaTime) {
			variable.outOfAreaTime = signal.gpsTime;
			return null;
		}
		long time = (signal.gpsTime.getTime() - variable.outOfAreaTime.getTime()) / 1000L;
		if (time >= Integer.valueOf(rule.value1) * 60) {
			if (variable.lastAlarmTime108 == null) {
				variable.lastAlarmTime108 = signal.gpsTime;
				// 发送语音报警命令,生成报警
				String command = AlarmTool.getVoiceRemindingCommand(2);
				SendCommand.voiceReminding(signal.gpsNo, command);
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "您已驶离作业区域[" + time / 60L + "分" + time % 60L + "秒]";
				ai.keepTime = time;
				ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
				return ai;
			}
			long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime108.getTime()) / 1000L;
			if (time1 >= Integer.valueOf(rule.value1) * 60) {
				variable.lastAlarmTime108 = signal.gpsTime;
				String command = AlarmTool.getVoiceRemindingCommand(2);
				SendCommand.voiceReminding(signal.gpsNo, command);
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "您已驶离作业区域[" + time / 60L + "分" + time % 60L + "秒]";
				ai.keepTime = time;
				ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
				return ai;
			}
			return null;
		}
		return null;
	}
	
	/**
	 * 入区域报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm109(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (null == signal.areaId) {
			// 未设定报警区域、非工作时间、当前不在任一区域区域中
			variable.inAreaTime = null;
			variable.lastAlarmTime109 = null;
			return ai;
		}
		List<String> areaIds = Arrays.asList(rule.value1.toUpperCase().split(","));
		if (!areaIds.contains(signal.areaId)) {
			// 当前所处区域不在任一报警区域中
			variable.inAreaTime = null;
			variable.lastAlarmTime109 = null;
			return ai;
		}
		/*
		 * 当前在报警区域中
		 */
		if (null == variable.inAreaTime) {
			// 第一次进入报警区域, 记录该时间, 不报警
			variable.inAreaTime = signal.gpsTime;
		} else {
			// 持续在报警区域内
			// 间隔 delay 秒开始报警, 如果没设置持续时间或者持续时间为零, 则默认为300秒
			int delay = (null == rule.value2 || "".equals(rule.value2.trim()) ? 300 : Integer.valueOf(rule.value2) * 60);
			// 持续时间
			long time = (signal.gpsTime.getTime() - variable.inAreaTime.getTime()) / 1000;
			if (time >= delay) {
				// 需要报警
				if (null == variable.lastAlarmTime109) {
					// 第一次报警, 记录该时间
					variable.lastAlarmTime109 = signal.gpsTime;
					ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "您已进入区域" + signal.areaId + ",持续时间:[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
				} else {
					// 不是第一次报警
					long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime109.getTime()) / 1000L;
					if (time1 >= delay) {
						variable.lastAlarmTime109 = signal.gpsTime;
						ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
						ai.alarmMessage = "您已进入区域" + signal.areaId + ",持续时间:[" + time / 60L + "分" + time % 60L + "秒]";
						ai.keepTime = time;
						ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					}
				}
			}
		}
		return ai;
	}
	
	/**
	 * 非指定地点加水 ok
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm119(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		// if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
		// // 非排班时间内
		// return null;
		// }
		if (0 == vehicle.wateringAddPoints.size()) {
			// 未绑定加水点
			return ai;
		}
		if (1 != signal.isWaterAdding) {
			// 不在加水状态中
			return ai;
		}
		if (signal.speed > 5) {
			// 车速大于5
			return ai;
		}
		boolean isInPoint = false;
		for (List<LabelPoint> list : vehicle.wateringAddPoints.values()) {
			if (null == list || 0 == list.size()) {
				continue;
			}
			for (LabelPoint point : list) {
				double a = Tools.getTwoPointDistance(point.baiduLng, point.baiduLat, signal.baiduLng, signal.baiduLat);
				if (a <= ServerConfig.instance().collectionDistance) {
					// 在任一加水点附近
					isInPoint = true;
					break;
				}
			}
		}
		if (!isInPoint) {
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请您在指定的加水点加水!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}
	
	/**
	 * 非指定地点倾倒垃圾 ok
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm120(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		// if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
		// // 非工作时间段内
		// return null;
		// }
		if (0 == vehicle.dumpPoints.size()) {
			// 未绑定垃圾倾倒点
			return ai;
		}
		if (1 != signal.isWasteDumping) {
			// 不处于垃圾倾倒状态
			return ai;
		}
		if (signal.speed > 5) {
			// 车速大于5
			return ai;
		}
		boolean isInPoint = false;
		for (List<LabelPoint> list : vehicle.dumpPoints.values()) {
			if (null == list || 0 == list.size())
				continue;
			for (LabelPoint point : list) {
				double a = Tools.getTwoPointDistance(point.baiduLng, point.baiduLat, signal.baiduLng, signal.baiduLat);
				if (a <= ServerConfig.instance().collectionDistance) {
					// 在某一垃圾倾倒点附近
					isInPoint = true;
					break;
				}
			}
		}
		if (!isInPoint) {
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请您在指定的倾倒点倾倒垃圾!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}
	
	/**
	 * 非指定地点污水排放 ok
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm121(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		// if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
		// // 不在排班时间段内
		// return null;
		// }
		if (0 == vehicle.dischargePoints.size()) {
			// 未绑定污水排放点
			return ai;
		}
		if (1 != signal.isSewageEmission) {
			// 车辆不处于污水排放状态
			return ai;
		}
		if (signal.speed > 5) {
			// 当前车速大于5
			return ai;
		}
		boolean isInPoint = false;
		for (List<LabelPoint> list : vehicle.dischargePoints.values()) {
			if (null == list || 0 == list.size())
				continue;
			for (LabelPoint point : list) {
				double a = Tools.getTwoPointDistance(point.baiduLng, point.baiduLat, signal.baiduLng, signal.baiduLat);
				if (a <= ServerConfig.instance().collectionDistance) {
					// 在某一污水排放点附近
					isInPoint = true;
					break;
				}
			}
		}
		if (!isInPoint) {
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "请您在指定的排污点排放污水!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}

	/**
	 * 未按规定时间上班
	 * 这块逻辑移到DutyReportCal类中
	 * @param vehicle
	 * @param signal
	 * @param rule
	 */
	public void alarm123(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {

	}
	
	/**
	 * 垃圾收集点未去
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm124(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {

		return null;
	}
	
	/**
	 * 清扫路段未去
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm125(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		/*
		 * 该部分逻辑在 alarm126中 一起统计
		 */
		return null;
	}
	
	/**
	 * 未达到清扫遍数
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm126(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		Logger.debug("zybs" + signal.gpsNo, "---------------------------开始检测作业遍数---------------------------");
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
			// 车辆当前不在排班时间内
			Logger.debug("zybs" + signal.gpsNo, "当前不在排班时间内, 当前Gps时间: " + sdf1.format(signal.gpsTime));
			variable.passCheckPoints.clear();
			return null;
		}
		if (null == vehicle.getAreas() || 0 == vehicle.getAreas().size()) {
			// 车辆未绑定区域/路线
			Logger.debug("zybs" + signal.gpsNo, "车辆未绑定区域/路线");
			variable.passCheckPoints.clear();
			return null;
		}
		if (null == signal.areaId) {
			// 车辆当前不在区域中
			Logger.debug("zybs" + signal.gpsNo, "车辆当前不在任一区域/路线中");
			variable.passCheckPoints.clear();
			return null;
		}
		if (0 == signal.isInWork) {
			// 车辆当前不处于工作状态
			Logger.debug("zybs" + signal.gpsNo, "车辆当前不处于工作状态中");
			variable.passCheckPoints.clear();
			return null;
		}
		Area area = vehicle.getAreas().get(signal.areaId);
		if (null == area.roads || 0 == area.roads.size()) {
			// 车辆所在区域未绑定路段
			Logger.debug("zybs" + signal.gpsNo, "车辆当前所处区域/路线: " + area.name + "未绑定路段");
			variable.passCheckPoints.clear();
			return null;
		}
		// 上一个定位点, 看做直线起点
		Point last = new Point(vehicle.lastGps.baiduLat, vehicle.lastGps.baiduLng);
		// 当前定位点, 看做直线终点
		Point now = new Point(signal.baiduLat, signal.baiduLng);
		// 检测点半径
		double checkRadius = ServerConfig.instance().checkPointDistance;
		// 遍历该区域/路线上的所有路段
		for (Road road : area.roads.values()) {
			if (null == road.checkPoints || 0 == road.checkPoints.size()) {
				Logger.debug("zybs" + signal.gpsNo, "路段:" + road.roadName + " 未设置路段检测点");
				continue;
			}
			for (RoadCheckPoint point : road.checkPoints.values()) {
				double distance = Tools.pointToLine(last, now, point);
				if (checkRadius >= distance) {
					// 点到直线的距离小于检测点半径, 说明经过或正在该检测点范围
					if (!variable.passCheckPoints.contains(point.checkPointId)) {
						variable.recondWorkPoint(road, point);
						if (variable.workTimesMap.containsKey(point.checkPointId)) {
							int times = variable.workTimesMap.get(point.checkPointId);
							variable.workTimesMap.put(point.checkPointId, times + 1);
							Logger.debug("zybs" + signal.gpsNo, "车辆第" + (times + 1) + "次进入检测点: " + point.checkPointId + " 范围内, 作业回数加1");
						} else {
							// 第一次进入/经过该检测点, 该检测点的实际清扫回数+1
							Logger.debug("zybs" + signal.gpsNo, "车辆第一次进入检测点: " + point.checkPointId + " 范围内, 记录作业回数为1次");
							variable.workTimesMap.put(point.checkPointId, 1);
						}
					} else {
						Logger.debug("zybs" + signal.gpsNo, "车辆未离开检测点: " + point.checkPointId + " 范围, 不增加实际作业回数");
					}
				} else {
					if (variable.passCheckPoints.contains(point.checkPointId)) {
						variable.passCheckPoints.remove(point.checkPointId);
						Logger.debug("zybs" + signal.gpsNo, "车辆距离检测点: " + point.checkPointId + distance + " 米, 移除缓存中的记录");
					} else {
						Logger.debug("zybs" + signal.gpsNo, "车辆距离检测点: " + point.checkPointId + distance + " 米");
					}
				}
				// 当前坐标点到检测点的距离, 用以判断是否小于检测半径
				double dis = Tools.getTwoPointDistance(now, point);
				if (dis <= checkRadius) {
					// 距离小于半径, 说明当前坐标点在以检测点为圆心, 检测距离为半径的圆内, 记录该坐标点
					variable.passCheckPoints.add(point.checkPointId);
					Logger.debug("zybs" + signal.gpsNo, "车辆在检测点: " + point.checkPointId +  "范围内, 将该点记录到缓存中");
				} else {
					if (variable.passCheckPoints.contains(point.checkPointId))
						variable.passCheckPoints.remove(point.checkPointId);
					Logger.debug("zybs" + signal.gpsNo, "当前车辆不在检测点: " + point.checkPointId + " 范围内");
				}
			}
		}
		return null;
	}
	
	/**
	 * 在规定时间内未完成作业任务
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm127(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {return null;}
	
	/**
	 * 高峰时段出去工作的
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm128(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (0 == signal.isInWork) {
			variable.lastAlarmTime128 = null;
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		String cur = sdf.format(signal.gpsTime);
		if ((cur.compareTo(rule.value1) > 0 && cur.compareTo(rule.value2) < 0)
				|| (cur.compareTo(rule.value3) > 0 && cur.compareTo(rule.value4) < 0)) {
			// 在上班高峰时间段内, 或者在下班高峰时间段内, 处于工作状态, 报警
			if (null == variable.lastAlarmTime128) {
				variable.lastAlarmTime128 = signal.gpsTime;
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "请勿在高峰时间段内工作!";
				ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
				return ai;
			} else {
				long time = (signal.gpsTime.getTime() - variable.lastAlarmTime128.getTime()) / 1000L;
				if (time >= 300L) {
					variable.lastAlarmTime128 = signal.gpsTime;
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "请勿在高峰时间段内工作!";
					ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
					return ai;
				}
			}
		}
		return null;
	}
	
	/**
	 * 车辆作业时间超时
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm129(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (SignalCreator.calIsInWorkTime(true, vehicle, signal)) {
			// 工作时间段内，清缓存
			variable.workOverTime = null;
			variable.lastAlarmTime129 = null;
			return null;
		}
		if (signal.isInWork != 1) {
			// 非工作状态，清缓存
			variable.workOverTime = null;
			variable.lastAlarmTime129 = null;
			return null;
		}
		if (null == variable.workOverTime) {
			variable.workOverTime = signal.gpsTime;
		} else {
			long time = (signal.gpsTime.getTime() - variable.workOverTime.getTime()) / 1000;
			if (time >= (Integer.valueOf(rule.value1) * 60)) {
				// 违规持续时间超过设定阀值
				if (null == variable.lastAlarmTime129) {
					variable.lastAlarmTime129 = signal.gpsTime;
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "车辆作业时间超时";
					ai.keepTime = 0;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
			}
		}
		return null;
	}
	
	/**
	 * 130.停车未熄火报警
	 * 
	 * @param vehicle
	 * @param bean
	 * @param rule
	 */
	public AlarmInfo alarm130(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (0 == signal.accStatus) {
			variable.unFlameOutWhenParkingTime = null;
			variable.lastAlarmTime130 = null;
			return null;
		}
		if (signal.speed > 0.0D) {
			variable.unFlameOutWhenParkingTime = null;
			variable.lastAlarmTime130 = null;
			return null;
		}
		if (null == variable.unFlameOutWhenParkingTime) {
			variable.unFlameOutWhenParkingTime = signal.gpsTime;
			return null;
		}
		long time = (signal.gpsTime.getTime() - variable.unFlameOutWhenParkingTime.getTime()) / 1000L;
		if (time >= Integer.valueOf(rule.value1) * 60) {
			if (null == variable.lastAlarmTime130) {
				variable.lastAlarmTime130 = signal.gpsTime;
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "停车未熄火持续[" + time / 60L + "分" + time % 60L + "秒]";
				ai.keepTime = time;
				ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
				return ai;
			}
			long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime130.getTime()) / 1000L;
			if (time1 >= Integer.valueOf(rule.value1) * 60) {
				variable.lastAlarmTime130 = signal.gpsTime;
				AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
				ai.alarmMessage = "停车未熄火持续[" + time / 60L + "分" + time % 60L + "秒]";
				ai.keepTime = time;
				ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
				return ai;
			}
		}
		return null;
	}

	/**
	 * 未按收集点顺序工作的
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm131(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (!SignalCreator.calIsInWorkTime(false, vehicle, signal))
			// 非工作时间段内
			return null;
		if (null == vehicle.collectionPoints || 0 == vehicle.collectionPoints.size())
			// 车辆未绑定收集点
			return null;
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		double distance = ServerConfig.instance().collectionDistance;
		// 车辆上一个坐标点
		Point last = new Point(vehicle.lastGps.baiduLat, vehicle.lastGps.baiduLng);
		// 当前坐标点
		Point now = new Point(signal.baiduLat, signal.baiduLng);
		for (List<LabelPoint> points : vehicle.collectionPoints.values()) {
			if (null == points || 0 == points.size())
				continue;
			for (LabelPoint point : points) {
				double dis = Tools.pointToLine(last, now, point);
				if (dis <= distance) {
					if (!variable.collectionList.contains(point)) {
						variable.collectionList.add(point);
					}
					if (!variable.collPoints.contains(point)) {
						variable.collPoints.add(point);
					}
				}
			}
		}
		return null;
	}
	
	/**
	 * 垃圾箱未放下
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm132(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.binStatus && signal.speed >= 5.0D) {
			AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "垃圾箱未放下,请检查!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
			return ai;
		}
		return null;
	}
	
	/**
	 * 填充箱未放下 ok
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm133(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if (1 == signal.stuffStatus && signal.speed >= 5.0D) {
	      AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
	      ai.alarmMessage = "填充箱未放下,请检查!";
	      ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
	      return ai;
	    }
	    return null;
	}
	
	/**
	 * 134.未按规定时间下班 ok
	 * 这块逻辑移到DutyReportCal类中
	 * @param bean
	 * @param ar
	 * @param vehicle
	 */
	public void alarm134(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {

	}
	
	/**
	 * 非指定地点装载垃圾
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm135(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		// if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
		// // 车辆不在排班时间段内
		// return null;
		// }
		if (!"03".equals(vehicle.kindCode) && !"07".equals(vehicle.kindCode)) {
			// 不是压缩或餐厨车
			return null;
		}
		if (signal.accStatus == 0) {
			// 车辆acc关闭
			return null;
		}
		if (signal.speed > 5.0) {
			// 车速大于5
			return null;
		}
		if (signal.strengthStatus == 0) {
			// 取力器关闭
			return null;
		}
		if ((1 == signal.equipmentType && 1 == signal.binStatus)
				|| (3 == signal.equipmentType && 1 == signal.stuffStatus)) {
			// 填装箱/垃圾箱打开
			return null;
		}
		if (null == vehicle.garbagePoints || 0 == vehicle.garbagePoints.size()) {
			// 未绑定垃圾收集点
			return null;
		}
		Point point = new Point(signal.baiduLat, signal.baiduLng);
		double garbageCollectionDistance = ServerConfig.instance().garbageCollectionDistance;

		boolean flag = true;
		for (List<GarbageCollectionPoint> list : vehicle.garbagePoints.values()) {
			if (null != list && 0 != list.size()) {
				for (GarbageCollectionPoint p : list) {
					double distance = Tools.getTwoPointDistance(p, point);
					if (distance < garbageCollectionDistance) {
						// 在绑定的某一垃圾收集点附近作业
						flag = false;
						break;
					}
				}
				if (!flag) {
					break;
				}
			}
		}
		AlarmInfo ai = null;
		if (flag) {
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "车辆" + vehicle.plateNO + "在非指定地点装载垃圾!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}
	
	/**
	 * 非指定地点卸载垃圾
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm136(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		// if (!SignalCreator.calIsInWorkTime(false, vehicle, signal)) {
		// // 不在排班时间段内
		// return null;
		// }
		if (!"03".equals(vehicle.kindCode) && !"07".equals(vehicle.kindCode)) {
			// 不是压缩车或餐厨车
			return null;
		}
		if (signal.accStatus == 0) {
			// 车辆acc关闭
			return null;
		}
		if (signal.speed > 5.0D) {
			// 车速大于5
			return null;
		}
		if ((1 == signal.equipmentType && 0 == signal.binStatus)
				|| (3 == signal.equipmentType && 0 == signal.stuffStatus)) {
			// 填装箱/垃圾箱关闭
			return null;
		}
		if (null == vehicle.garbagePoints || 0 == vehicle.garbagePoints.size()) {
			// 未绑定垃圾收集点
			return null;
		}
		Point point = new Point(signal.baiduLat, signal.baiduLng);
		double garbageCollectionDistance = ServerConfig.instance().garbageCollectionDistance;
		boolean flag = true;
		for (List<GarbageCollectionPoint> list : vehicle.garbagePoints.values()) {
			if (null != list && 0 != list.size()) {
				for (GarbageCollectionPoint p : list) {
					double distance = Tools.getTwoPointDistance(p, point);
					if (distance < garbageCollectionDistance) {
						// 在绑定的某一垃圾收集点附近作业
						flag = false;
						break;
					}
				}
				if (!flag) {
					break;
				}
			}
		}
		AlarmInfo ai = null;
		if (flag) {
			ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			ai.alarmMessage = "车辆" + vehicle.plateNO + "在非指定地点卸载垃圾!";
			ai.alarmLevel = AlarmTool.getAlarmLevel(0L, rule);
		}
		return ai;
	}
	
	/**
	 * 非作业区域/路线滞留报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm137(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		AlarmInfo ai = null;
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (0 == signal.accStatus) { //TODO
			// acc关,不报警
			variable.inDefaultAreaTime = null;
			variable.lastAlarmTime137 = null;
			return ai;
		}
		if (null == signal.areaId) {
			// 车辆当前不在任何区域中,不报警
			variable.inDefaultAreaTime = null;
			variable.lastAlarmTime137 = null;
			return ai;
		}
		Area defaultArea = null;
		Point point = new Point(signal.baiduLat, signal.baiduLng);
		for (Area area : vehicle.areaMap.values()) {
			if (area.isInArea(point)) {
				if ("07".equals(area.kind)) {
					defaultArea = area;
					break;
				}
			}
		}
		if (null != defaultArea) {
			// 当前在非作业区域/路线中
			if (null == variable.inDefaultAreaTime) {
				// 第一次进入非作业区域/路线,记录该时间
				variable.inDefaultAreaTime = signal.gpsTime;
			} else {
				long time = (signal.gpsTime.getTime() - variable.inDefaultAreaTime.getTime()) / 1000;
				if (time >= Integer.valueOf(rule.value1) * 60) {
					// 滞留时间超过设定的阀值
					if (null == variable.lastAlarmTime137) {
						// 之前从未报警,产生一条报警
						variable.lastAlarmTime137 = signal.gpsTime;
						ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
		            	ai.alarmMessage = "进入非作业区域/路线[" + time / 60 + "分" + time % 60 + "秒]";
		            	ai.keepTime = time;
		            	ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					} else {
						// 之前已经报警
						long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime137.getTime()) / 1000;
						if (time1 >= Integer.valueOf(rule.value1) * 60) {
							// 持续型报警,且超过设定阀值
							variable.lastAlarmTime137 = signal.gpsTime;
							ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
			            	ai.alarmMessage = "进入非作业区域/路线[" + time / 60 + "分" + time % 60 + "秒]";
			            	ai.keepTime = time;
			            	ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
						}
					}
				}
			}
		}
		return ai;
	}
	
	/**
	 * 行车超速报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm204(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (signal.speed < Double.valueOf(rule.value1)) {
			// 行驶速度小于阀值
			variable.overSpeedTime204 = null;
			variable.lastAlarmTime204 = null;
			return null;
		}
		if (0 == signal.accStatus) {
			variable.overSpeedTime204 = null;
			variable.lastAlarmTime204 = null;
			return null;
		}
		if (null == variable.overSpeedTime204) {
			variable.overSpeedTime204 = signal.gpsTime;
		} else {
			// 秒
			long time = (signal.gpsTime.getTime() - variable.overSpeedTime204.getTime()) / 1000L;
			if (time > Integer.valueOf(rule.value2) * 60) {
				// 超速持续时间大于阀值,报警
				if (null == variable.lastAlarmTime204) {
					variable.lastAlarmTime204 = signal.gpsTime;
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "行驶速度规定为[" + rule.value1 + "km/h], 您已超速行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
				long time1 = (signal.gpsTime.getTime() - variable.lastAlarmTime204.getTime()) / 1000L;
				if (time1 > Integer.valueOf(rule.value2) * 60) {
					variable.lastAlarmTime204 = signal.gpsTime;
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmMessage = "行驶速度规定为[" + rule.value1 + "km/h], 您已超速行驶[" + time / 60L + "分" + time % 60L + "秒]";
					ai.keepTime = time;
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					return ai;
				}
			}
		}
		return null;
	}
	
	/**
	 * 车辆离线报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm205(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		return null;
	}
	
	/**
	 * 车辆副发时长超过规定时间报警
	 * @param vehicle
	 * @param signal
	 * @param rule
	 * @return
	 */
	public AlarmInfo alarm206(Vehicle vehicle, GpsSignal signal, AlarmRule rule) {
		if(rule.value1==null || rule.value2==null){
			return null;
		}
		// 获取缓存变量
		VariableData variable = CacheManager.instance().getVariable(signal.gpsNo);
		if (variable.lastAlarmTime206 == null) {
			// 第一次报警时间
			variable.lastAlarmTime206 = signal.gpsTime;
		} else {
			//获取缓存里面的时间
			long gapTime = CacheManager.instance().subSpeedMap.get(signal.gpsNo)==null?0:CacheManager.instance().subSpeedMap.get(signal.gpsNo);
			//获取数据库中累计时间
			long dbTime = CacheManager.instance().subSpeedTimeMap.get(signal.gpsNo)==null?0:CacheManager.instance().subSpeedTimeMap.get(signal.gpsNo);;
			//当前gps时间-上一次报警时间
			long time = (signal.gpsTime.getTime()-variable.lastAlarmTime206.getTime())/1000L;
			//设置的报警间隔时间
			long setGapTime = Integer.valueOf(rule.value2==null?"0":rule.value2) * 60;
			if (gapTime+dbTime >= Integer.valueOf(rule.value1==null?"0":rule.value1)*60*60) {
				if(time >= setGapTime){
					AlarmInfo ai = AlarmTool.createAlarmInfo(vehicle, signal, rule);
					ai.alarmLevel = AlarmTool.getAlarmLevel(time, rule);
					ai.alarmMessage = "副发时间太长，请对车辆进行保养!";
					//将数据插入到报警表中
					CacheManager.instance().getAlarmSaveQueue(vehicle.company).offer(ai);
					variable.lastAlarmTime206 = signal.gpsTime;
				}
			}
		}
		return null;
	}		

}
